package com.example;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LogController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @PostMapping("/send-log")
    public String sendLog(@RequestBody LogRequest logRequest) {
        String message = logRequest.getMessage();
        rabbitTemplate.convertAndSend("log_exchange", "log_key", message);
        return "Log message sent: " + message;
    }

    public static class LogRequest {
        private String message;

        // Getter and Setter
        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }
    }
}

